<template>
	<view>
		<image src="../../static/image/logo2.png" class="logo" mode=""></image>
		<view class="formlist">
			<view class="formItem">
				<input type="text" v-model="telphone" placeholder="请输入手机号" />
			</view>
			<view class="formItem">
				<input type="text" placeholder="请输入验证码" v-model="code"/>
				<view class="getCode" @click="getCode"
							:class="{activeCode:codeFlag}">{{codeTxt}}</view>
			</view>
			<view class="formItem">
				<input type="text" v-model="password" placeholder="请输入密码" />
			</view>
		</view>
		<view class="registerBtn" @click="register">
			注册
		</view>
		<view class="loginTxt">
			已有账号？<navigator url="../login/login" hover-class="none" class="">点击登录</navigator>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				telphone:'',
				password:'',
				codeTxt:'获取验证码',
				codeFlag:true,
				code:''
			}
		},
		methods: {
			getCode(){
				if(!this.check.telphone(this.telphone)){return;}
				
				this.sendMessage()
			},
			
			sendMessage(){
				uni.request({
					url:this.apiUrl + '/index/getSmsCode',
					method:'POST',
					data:{
						telphone:this.telphone
					},
					success:(res)=>{
						console.log(res.data.result)
						if(res.data.result != 0){
							uni.showToast({
								title:res.data.errmsg,
								icon:'none'
							})
						}else{
							if( this.codeFlag == false){
								return
							}
							this.codeFlag = false
							var time=10
							this.codeTxt="重新获取"+time;
							var timer = setInterval(()=>{
								if(time == 1){
									this.codeTxt = '获取验证码'
									this.codeFlag = true
									clearInterval(timer)
								}else{
									time--
									this.codeTxt="重新获取"+time;
								}
							},1000)
						}
					}
				})
			},
			
			register(){
				if(!this.check.telphone(this.telphone)){return;}
				if(!this.check.password(this.password)){return;}
				if(!this.check.code(this.code)){return;}
				uni.request({
					url:this.apiUrl + '/index/register',
					method:'POST',
					data:{
						telphone:this.telphone,
						password:this.password,
						code:this.code
					},
					success:(res)=>{
						console.log(res)
					}
				})
			}
		}
	}
</script>

<style>
	.logo{
		width: 250rpx;
		height: 250rpx;
		margin: 70rpx auto 15rpx;
		display: block;
	}
	.formItem{
		height: 74rpx;
		padding-top: 36rpx;
		border-bottom: 1rpx solid #e5e5e5;
		margin: 0 100rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}
	.formItem input{
		font-size: 28rpx;
	}
	.getCode{
		background: #f7f7f7;
		color: #666;
		height: 60rpx;
		width: 180rpx;
		line-height: 60rpx;
		font-size: 24rpx;
		text-align: center;
	}
	.getCode.activeCode{
		background-color: #23baef;
		color: #fff;
	}
	.registerBtn{
		height: 86rpx;
		margin: 0 100rpx;
		background: #23baef;
		color: #fff;
		font-size: 28rpx;
		line-height: 86rpx;
		margin-top: 60rpx;
		border-radius: 10rpx;
		text-align: center;
	}
	.loginTxt{
		height: 120rpx;
		line-height: 120rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 24rpx;
	}
	.loginTxt navigator{
		color: #23baef;
		margin-left: 10rpx;
	}
</style>
